home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / SNDLIST- / CONVERT.C < prev    next >
Text File  |  1988-11-10  |  2KB  |  73 lines

  1. /*
  2.     Sound lister
  3.     "Convert.c"
  4. */
  5.  
  6. #include <sane.h>
  7. #include <ToolboxUtil.h>
  8.  
  9. static union {                        /* Largest possible positive double */
  10.     unsigned int plusdoubleparts[5];
  11.     double plusdouble;
  12. } max = { 0x7FFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF };
  13.  
  14. typedef struct {                    /* SANE environment flags word */
  15.     short    unused:1, round:2,
  16.             inexact:1, divbyzero:1, overflow:1, underflow:1, invalid:1,
  17.             lastround:1, precision:2, halts:5;
  18. } SANEenvword;
  19.  
  20. extern SANEenvword SANEglobalenv: 0xA4A;
  21.  
  22. #define    FOPSTR2DEC    (short)0x0002    /* Pascal string to decimal record */
  23. #define    FODEC2STR    (short)0x0003    /* Decimal record to Pascal string */
  24. #define    FOCSTR2DEC    (short)0x0004    /* C string to decimal record */
  25.  
  26. pascal void DecStr68K()    = 0xA9EE;    /* _Trap7 */
  27.  
  28. /* ----- Value of 2 raised to the X power ------------------------------ */
  29.  
  30. double exp2(x)
  31. double x;
  32. {
  33.     elems68k(&x, FOEXP2X);
  34.     if (SANEglobalenv.overflow)
  35.         return max.plusdouble;
  36.     return x;
  37. }
  38.  
  39. /* ----- Convert Fixed to string and vice versa ------------------------ */
  40.  
  41. void Fixed2String(x, s)
  42. register Fixed x;
  43. register unsigned char *s;
  44. {
  45.     double value;
  46.     Decimal dec;
  47.     DecForm form;
  48.  
  49.     form.style = FIXEDDECIMAL;
  50.     form.digits = 6;
  51.  
  52.     value = Fix2X(x);
  53.     fp68k(&form, &value, &dec, FFEXT+FOB2D);
  54.     /*Dec2Str(&form, &dec, s);*/
  55.     DecStr68K(&form, &dec, s, FODEC2STR);
  56. }
  57.  
  58. short String2Fixed(s, x)
  59. register unsigned char *s;
  60. register Fixed *x;
  61. {
  62.     double value;
  63.     Decimal dec;
  64.     short index;
  65.     short validPrefix;
  66.  
  67.     /*Str2Dec(s, &index, &dec, &validPrefix);*/
  68.     DecStr68K(s, &index, &dec, &validPrefix, FOPSTR2DEC);
  69.     fp68k(&dec, &value, FFEXT+FOD2B);
  70.     *x = X2Fix(&value);
  71.     return index;
  72. }
  73.